/* eslint-disable @typescript-eslint/no-var-requires */
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const path = require('path')

module.exports = {
  entry: path.resolve(__dirname, '../src/index.ts'),
  output:
  {
    filename: 'bundle.[hash].js',
    path: path.resolve(__dirname, '../dist')
  },
  devtool: 'source-map',
  plugins:
  [
    new CopyWebpackPlugin({
      patterns: [
        { from: path.resolve(__dirname), to: "../static" },
      ],
    }),
    new HtmlWebpackPlugin({
      template: path. resolve(__dirname, '../src/index.html'),
      minify: true
    })
  ],
  resolve: {
    extensions: ['.ts', '.js'],
  },
  module:
  {
    rules:
    [
      // HTML
      {
        test: /\.(html)$/,
        use: ['html-loader']
      },
      // JS || TS
      {
        test: /\.(js|ts)$/,
        exclude: /node_modules/,
        use:
        [
          'babel-loader'
        ]
      },
      // Images
      {
        test: /\.(jpg|png|gif|svg)$/,
        use:
        [
          {
            loader: 'file-loader',
            options:
            {
              outputPath: 'assests/images/'
            }
          }
        ]
      },
      // Models
      {
        test: /\.(glb|gltf|fbx|obj)$/,
        use:
        [
          {
            loader: 'file-loader',
            options:
            {
              outputPath: 'assets/models/'
            }
          }
        ]
      },
      // MP3
      {
        test: /\.(mp3)$/,
        use:
        [
          {
            loader: 'file-loader',
            options: 
            {
              outputPath: 'assets/audios/'
            }
          }
        ]
      },
      // Shaders
      {
        test: /\.(glsl|vs|fs|vert|frag)$/,
        exclude: /node_modules/,
        use: [
          'raw-loader',
          'glslify-loader'
        ]
      }
    ]
  }
}